package net.csdra.wenhua.nanan.qiandao.web;

import net.csdra.wenhua.nanan.qiandao.domain.Record;
import net.csdra.wenhua.nanan.qiandao.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by xiaomi on 2017/2/21.
 */
@RestController
@RequestMapping("/qiandao/admin")
public class AdminController {

    @Autowired
    AdminService adminService;

    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public Map adminLogin(@RequestBody AdminService.AdminLogin adminLogin) {
        boolean result = adminService.adminLogin(adminLogin);
        Map<String,String> map = new HashMap<>();
        if(result){
            map.put("href","/admin/admin.html");
        }else {
            map.put("href","/admin/adminLogin.html");
        }
        return map;
    }

    @RequestMapping("/deleteUserByUserId")
    public boolean deleteUserByUserId(String userId) {
        return adminService.deleteUserByUserId(userId);
    }

    @RequestMapping("/deleteCheckInByCheckInId")
    public boolean deleteCheckInByCheckInId(String checkInId) {
        return adminService.deleteCheckInByCheckInId(checkInId);
    }

    @RequestMapping("/getPagedRecord")
    public Page<Record> getPagedRecord(@RequestBody AdminService.GetPagedRecord getPagedRecord) {
        return adminService.getPagedRecord(getPagedRecord);
    }

}
